package com.jlt.service.account;

import java.util.LinkedHashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.jlt.entity.account.Resource;

/**
 * 从数据库查询URL--授权定义Map的实现类.
 * 
 * @author calvin
 */
@Component
@Transactional(readOnly = true)
public class ResourceManager  {
	@Autowired
	private AccountManager AccountManager;

	/**
	 * RequestMap生成接口,由用户自行实现从数据库或其它地方查询URL-授权关系定义.
	 * 
	 * 返回带顺序的URL-授权关系Map, key为受保护的URL, value为能访问该URL的授权名称列表,以','分隔.
	 *
	 * @author calvin
	 */
	public LinkedHashMap<String, String> getRequestMap() throws Exception {//NOSONAR
		List<Resource> resourceList = AccountManager.getUrlResourceWithAuthorities();

		LinkedHashMap<String, String> requestMap = new LinkedHashMap<String, String>(resourceList.size());
		for (Resource resource : resourceList) {
			requestMap.put(resource.getResString(), resource.getAuthNames());
		}
		return requestMap;
	}
	
	public AccountManager getAccountManager() {
		return AccountManager;
	}
	
	public void setAccountManager(AccountManager accountManager) {
		AccountManager = accountManager;
	}
}
